//
//  XYProgressHUD.h
//  XYCustomAlertView
//
//  Created by gao chenyang on 2019/11/1.
//  Copyright © 2019 gao chenyang. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
NS_ASSUME_NONNULL_BEGIN

typedef NS_ENUM(NSInteger, XYProgressHUDMode) {
    /** Progress is shown using an UIActivityIndicatorView. This is the default. */
    XYProgressHUDModeIndeterminate,
    /** Progress is shown using a round, pie-chart like, progress view. */
    XYProgressHUDModeDeterminate,
    /** Progress is shown using a horizontal progress bar */
//    XYProgressHUDModeDeterminateHorizontalBar,
    /** Progress is shown using a ring-shaped progress view. */
    XYProgressHUDModeAnnularDeterminate,
    /** Shows a custom view */
    XYProgressHUDModeCustomView,
    /** Shows only labels */
    XYProgressHUDModeText
};

typedef NS_ENUM(NSInteger, XYProgressHUDAnimation) {
    /** Opacity animation */
    XYProgressHUDAnimationFade,
    /** Opacity + scale animation */
    XYProgressHUDAnimationZoom,
    XYProgressHUDAnimationZoomOut = XYProgressHUDAnimationZoom,
    XYProgressHUDAnimationZoomIn
};
//返回对象
#ifndef XY_INSTANCETYPE
#if __has_feature(objc_instancetype)
#define XY_INSTANCETYPE instancetype
#else
#define XY_INSTANCETYPE id
#endif
#endif

#if NS_BLOCKS_AVAILABLE
typedef void (^XYProgressHUDCompletionBlock)(void);
#endif

@interface XYProgressHUD : UIView
//toast 显示时间
@property (nonatomic, assign) NSInteger showTime;

//是否阻止UI操作 默认是阻止UI操作
@property (nonatomic, assign) BOOL isBlockUI;
/**
 * HUD弹出样式
 */
@property (nonatomic,assign) XYProgressHUDMode mode;

/**
 * 动画类型
 */
@property (nonatomic,assign) XYProgressHUDAnimation animationType;

/**
 * 显示文字
 * 设置 @"",将不会被显示
 */
@property (nonatomic,copy) NSString *labelText;

/**
 * 详情文字
 */
@property (nonatomic,copy) NSString *detailsLabelText;
@property (nonatomic,copy) NSAttributedString *attriDetailsLabelText;

//自定义view
@property (nonatomic,strong) UIView *customView;

/**
 * HUD显示的透明度. 默认 0.8 (80% opacity).
 */
@property (nonatomic,assign) float opacity;

/**
 * HUD 显示的背景颜色  Defaults to black.
 */
@property (nonatomic,strong) UIColor *color;

/**
 * The x-axis offset of the HUD relative to the centre of the superview.
 */
@property (nonatomic, assign) float xOffset;

/**
 * The y-axis offset of the HUD relative to the centre of the superview.
 */
@property (nonatomic, assign) float yOffset;

/**
 * The amount of space between the HUD edge and the HUD elements (labels, indicators or custom views).
 * Defaults to 20.0
 */
@property (nonatomic, assign) float margin;

/**
 * The corner radius for the HUD
 * Defaults to 10.0
 */
@property (nonatomic, assign) float cornerRadius;

/**
 * Cover the HUD background view with a radial gradient.
 */
@property (nonatomic, assign) BOOL dimBackground;

/*
 * Grace period is the time (in seconds) that the invoked method may be run without
 * showing the HUD. If the task finishes before the grace time runs out, the HUD will
 */
@property (nonatomic, assign) float graceTime;

/**
 * The minimum time (in seconds) that the HUD is shown.
 * Defaults to 0 (no minimum show time).
 */
@property (nonatomic, assign) float minShowTime;

/**
 * Indicates that the executed operation is in progress. Needed for correct graceTime operation.
 */
@property (nonatomic, assign) BOOL taskInProgress;

/**
 * Removes the HUD from its parent view when hidden.
 * Defaults to NO.
 */
@property (nonatomic, assign) BOOL removeFromSuperViewOnHide;

/**
 * Font to be used for the main label. Set this property if the default is not adequate.
 */
@property (nonatomic,strong) UIFont* labelFont;

/**
 * Color to be used for the main label. Set this property if the default is not adequate.
 */
@property (nonatomic,strong) UIColor* labelColor;

/**
 * Font to be used for the details label. Set this property if the default is not adequate.
 */
@property (nonatomic,strong) UIFont* detailsLabelFont;

/**
 * Color to be used for the details label. Set this property if the default is not adequate.
 */
@property (nonatomic,strong) UIColor* detailsLabelColor;

/**
 * The color of the activity indicator. Defaults to [UIColor whiteColor]
 * Does nothing on pre iOS 5.
 */
@property (nonatomic,strong) UIColor *activityIndicatorColor;

/**
 * The progress of the progress indicator, from 0.0 to 1.0. Defaults to 0.0.
 */
@property (nonatomic,assign) float progress;

/**
 * The minimum size of the HUD bezel. Defaults to CGSizeZero (no minimum size).
 */
@property (nonatomic,assign) CGSize minSize;


/**
 * The actual size of the HUD bezel.
 * You can use this to limit touch handling on the bezel area only.
 */
@property (nonatomic, assign, readonly) CGSize size;


/**
 * Force the HUD dimensions to be equal if possible.
 */
@property (nonatomic,assign, getter = isSquare) BOOL square;

/**
 * A block that gets called after the HUD was completely hidden.
 */
@property (nonatomic, copy) XYProgressHUDCompletionBlock completionBlock;
/**
 创建一个HUD对象

 @param view 需要添加到什么视图上
 @param animated 是否有动画
 @return 返回HUD对象
 */
+ (XY_INSTANCETYPE)showHUDAddedTo:(UIView *)view animated:(BOOL)animated;

/**
 隐藏HUD

 @param view 隐藏view上的HUD
 @param animated 是否有动画
 @return BOOL YES 表示找到对应的HUD并移除 ，否则是NO
 */
+ (BOOL)hideHUDForView:(UIView *)view animated:(BOOL)animated;

+ (NSArray *)allHUDsForView:(UIView *)view;

- (id)initWithWindow:(UIWindow *)window;

- (id)initWithView:(UIView *)view;

- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block;

- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block completionBlock:(void (^)(void))completion;

- (void)showAnimated:(BOOL)animated whileExecutingBlock:(dispatch_block_t)block onQueue:(dispatch_queue_t)queue;

- (void)showAnimated:(BOOL)animated
 whileExecutingBlock:(dispatch_block_t)block
             onQueue:(dispatch_queue_t)queue
     completionBlock:(nullable XYProgressHUDCompletionBlock)completion;

- (void)show:(BOOL)animated;

- (void)hide:(BOOL)animated;

- (void)hide:(BOOL)animated afterDelay:(NSTimeInterval)delay;
@end

NS_ASSUME_NONNULL_END
